/**
 * 
 */
package com.fg.exemplocrudengenhariadesoftware.daobd;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.apache.log4j.Logger;

import com.fg.exemplocrudengenhariadesoftware.model.Escola;

/**
 * @author endrigo
 *
 */
public class EscolaDao {
	private JDBCUitl JDBCUitl;
	private Connection conexaoBD;
	Logger logger;

	public EscolaDao() {
		JDBCUitl = new JDBCUitl();
		logger = Logger.getLogger(this.getClass().getName());
	}

	public void insere(Escola escola) throws ErroAoConectarBDException {
		PreparedStatement preparedStatement = null;
		String stringSQL = "";

		try {
			conexaoBD = JDBCUitl.getConexaoBd();
			if (conexaoBD != null) {
				stringSQL = "INSERT INTO ESCOLA (ID, NOME) VALUES (?, ?)";
				logger.debug("insert:" + stringSQL);
				try {
					preparedStatement = conexaoBD.prepareStatement(stringSQL);
					preparedStatement.setInt(1, escola.getId());
					preparedStatement.setString(2, escola.getNome());
					preparedStatement.executeUpdate();
				} catch (Exception e1) {
					logger.error("erro ao inserir escola:" + escola.toString());
				}
			}
		} catch (Exception e) {
			throw new ErroAoConectarBDException();
		}
	}
}
